package com.xiaoshuidi.cloud.module.rooms.controller.app.map;

import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.framework.common.pojo.PageResult;
import com.xiaoshuidi.cloud.framework.security.core.util.SecurityFrameworkUtils;
import com.xiaoshuidi.cloud.framework.tenant.core.context.TenantContextHolder;
import com.xiaoshuidi.cloud.module.rooms.controller.app.map.vo.*;
import com.xiaoshuidi.cloud.module.rooms.enums.ApiConstants;
import com.xiaoshuidi.cloud.module.rooms.service.MapService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.annotation.security.PermitAll;
import java.util.List;

/**
 * 地图找房相关接口
 * @author hans.zhang
 */
@Tag(name = "租客端 - 地图找房相关接口")
@RestController
@RequestMapping(ApiConstants.NAME + "/map")
@RequiredArgsConstructor
public class MapController {

    private final MapService mapService;

    @Operation(summary = "地图找房")
    @Parameters({
            @Parameter(name = "maxLongitude", description = "最大经度", required = true),
            @Parameter(name = "minLongitude", description = "最小经度", required = true),
            @Parameter(name = "maxLatitude", description = "最大纬度", required = true),
            @Parameter(name = "minLatitude", description = "最小纬度", required = true),
            @Parameter(name = "isConcentrated", description = "是否集中式", required = true),
            @Parameter(name = "district", description = "区域"),
            @Parameter(name = "monthRentalMin", description = "租金范围-下限"),
            @Parameter(name = "monthRentalMax", description = "租金范围-上限"),
            @Parameter(name = "longitude", description = "地铁站经度"),
            @Parameter(name = "latitude", description = "地铁站纬度"),
            @Parameter(name = "isWhole", description = "出租方式,是否整租 true:整租 false:合租"),
            @Parameter(name = "bedRoomNum", description = "户型-几室 1:一室 2:二室 3:三室 4:四室 5:其他"),
            @Parameter(name = "publicFacilities", description = "特色需求(公共设施)"),
            @Parameter(name = "roomHouseState", description = "房源状态 1：可租房源 2：全部房源", required = true),
            @Parameter(name = "zoom", description = "缩放等级", required = true),
    })
    @GetMapping("/mapfindroom")
    @PermitAll
    public CommonResult<List<GetMapRespVO>> mapFindRoom(@RequestParam("maxLongitude") Double maxLongitude,
                                                   @RequestParam("minLongitude") Double minLongitude,
                                                   @RequestParam("maxLatitude") Double maxLatitude,
                                                   @RequestParam("minLatitude") Double minLatitude,
                                                        Boolean isConcentrated,
                                                        String district,
                                                        Double monthRentalMin,
                                                        Double monthRentalMax,
                                                        Double longitude,
                                                        Double latitude,
                                                        Boolean isWhole,
                                                        Integer bedRoomNum,
                                                        String publicFacilities,
                                                   String roomHouseState,
                                                   @RequestParam("zoom") Double zoom){
        Long tenantId = TenantContextHolder.getTenantId();
        return mapService.getMap(maxLongitude, minLongitude, maxLatitude, minLatitude, zoom, tenantId,
                isConcentrated, district, monthRentalMin, monthRentalMax, longitude, latitude, isWhole, bedRoomNum, publicFacilities, roomHouseState);
    }

    @PermitAll
    @Operation(summary = "地图找房-搜索")
    @Parameters({
            @Parameter(name = "searchBox", description = "搜索框内容"),
    })
    @GetMapping("/map-find-search")
    public CommonResult<PageResult<GetMapRespVO>> mapFindSearch(MapFindSearchReqVO reqVO){
        Long tenantId = TenantContextHolder.getTenantId();
        return mapService.mapFindSearch(reqVO.getSearchBox(), reqVO.getIsConcentrated(), reqVO.getRoomHouseState(), reqVO.getPageNo(), reqVO.getPageSize(), tenantId);
    }

    @Operation(summary = "地图找房-根据区域获取街道房源情况")
    @Parameters({
            @Parameter(name = "district", description = "区域", required = true),
            @Parameter(name = "street", description = "街道", required = true)
    })
    @PostMapping("/get-street-info-by-district")
    @PermitAll
    public CommonResult<List<GetMapRespVO>> getStreetInfoByDistrict(@RequestBody GetStreetInfoByDistrictReqVO reqVO){
        Long tenantId = TenantContextHolder.getTenantId();
        return mapService.getStreetInfoByDistrict(reqVO.getDistrict(), reqVO.getStreet(), tenantId);
    }

    @Operation(summary = "地图找房-查看小区房源情况")
    @Parameters({
          @Parameter(name = "apartmentAreaId", description = "小区id"),
          @Parameter(name = "pageNo", description = "页码"),
          @Parameter(name = "pageSize", description = "每页大小"),
    })
    @GetMapping("/getapartmentareainfo")
    @PermitAll
    public CommonResult<GetApartmentAreaInfoRespVO> getApartmentAreaInfo(@RequestParam("roomAreaId") Long roomAreaId,
                                                                               @RequestParam("pageNo") Integer pageNo,
                                                                               @RequestParam("pageSize") Integer pageSize){
        Long tenantId = TenantContextHolder.getTenantId();
        return mapService.getApartmentAreaInfo(roomAreaId, tenantId, pageNo, pageSize);
    }

    @Operation(summary = "通勤时间找房")
    @Parameters({
            @Parameter(name = "address", description = "地址", required = true),
            @Parameter(name = "mode", description = "通勤方式", required = true),
            @Parameter(name = "minute", description = "时间(分钟)", required = true),
            @Parameter(name = "viewMode", description = "查看模式 1：公寓 2：（合租）房源", required = true),
            @Parameter(name = "pageNum", description = "第几页", required = true),
            @Parameter(name = "pageSize", description = "每页大小", required = true),
    })
    @GetMapping("/commutingtimefindroom")
    @PermitAll
    public CommonResult<PageResult<CommutingRimeFindRoomRespVO>> commutingTimeFindRoom(
                                                                                   @RequestParam("address") String address,
                                                                                   @RequestParam("lat") Double lat,
                                                                                   @RequestParam("lng") Double lng,
                                                                                   @RequestParam("minute") Integer minute,
                                                                                   @RequestParam("mode") String mode,
                                                                                   @RequestParam("viewMode") Integer viewMode,
                                                                                   @RequestParam("pageNum") Integer pageNum,
                                                                                   @RequestParam("pageSize") Integer pageSize){
        Long tenantId = TenantContextHolder.getTenantId();
        return mapService.commutingtimefindroom(address, lat, lng, minute, mode, viewMode, pageNum, pageSize, tenantId);
    }

    @Operation(summary = "通勤距离找房")
    @Parameters({
            @Parameter(name = "address", description = "地址", required = true),
            @Parameter(name = "distance", description = "距离（千米）", required = true),
            @Parameter(name = "viewMode", description = "查看模式 1：公寓 2：（合租）房源", required = true),
            @Parameter(name = "pageNum", description = "第几页", required = true),
            @Parameter(name = "pageSize", description = "每页大小", required = true),
    })
    @GetMapping("/commutingdistancefindroom")
    @PermitAll
    public CommonResult<PageResult<CommutingDistanceFindRoomRespVO>> commutingDistanceFindRoom(
                                                                                               @RequestParam("address") String address,
                                                                                               @RequestParam("lat") Double lat,
                                                                                               @RequestParam("lng") Double lng,
                                                                                               @RequestParam("distance") Integer distance,
                                                                                               @RequestParam("viewMode") Integer viewMode,
                                                                                               @RequestParam("pageNum") Integer pageNum,
                                                                                               @RequestParam("pageSize") Integer pageSize){
        Long tenantId = TenantContextHolder.getTenantId();
        return mapService.commutingDistanceFindRoom(address, lat, lng, distance, viewMode, pageNum, pageSize, tenantId);
    }


    @Operation(summary = "同步room_street_latlon表中的区域,街道经纬度到redis")
    @GetMapping("/snycLatLonToRedis")
    @PermitAll
    public CommonResult<Boolean> getHFLatLon(){
        return mapService.snycLatLonToRedis();
    }

    @Operation(summary = "获取所有地铁线路")
    @GetMapping("/metro-route")
    @PermitAll
    public CommonResult<List<MetroRouteRespVO>> getMetroRoute(){
        return CommonResult.success(mapService.getMetroRoute());
    }

    @Operation(summary = "获取地铁线路下的站点")
    @GetMapping("/metro-site")
    @PermitAll
    public CommonResult<List<MetroSiteRespVO>> getMetroSite(@RequestParam("id") Long id){
        return CommonResult.success(mapService.getMetroSite(id));
    }


}
